package com.itheima.xinxi.system.dao;

import com.itheima.xinxi.system.domain.Teacher;

/**
 * 操作老师数据的类
 * 增删改查
 */
public class TeacherDao {
   private  Teacher[] teachers = new Teacher[20];

    //增
    public void addTeacher(Teacher teacher){
        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i]==null){
                teachers[i]=teacher;
                break;
            }
        }
    }
    //删
    public void deleteTeacherById(String id){
        //找见这个id 所在的位置
        int index = getIndex(id);
        teachers[index]=null;
    }

    //改
    public void updateTeacher(String id,Teacher teacher){
        int index = getIndex(id);
        teachers[index]=teacher;
    }
    //查所有
    public Teacher[] findAll(){
        return teachers;
    }
    //根据id找索引
    public int getIndex(String id){
        for (int i = 0; i < teachers.length; i++) {
            //teachers[i]
            if(teachers[i]!=null&&teachers[i].getId().equals(id)){
                return i;
            }

        }
        return -1;
    }
}
